<#assign pageName="流程审批用户管理">
<#function getUserName userId>
    <#if userList?has_content>
        <#list userList as user>
            <#if user.userId?string==userId?string>
                <#return user.uname>
            </#if>
        </#list>
    </#if>
    <#return "">
</#function>
<#function getDepName depid>
 alert(depid);
    <#if depList?has_content>
        <#list depList as dep>
            <#if depid!=""&dep.depId?string==depid?string>
                <#return dep.depName>
            </#if>
        </#list>
    </#if>
    <#return "">
</#function>
 <#function getUpperId depid>
    <#if depList?has_content>
        <#list depList as dep>
            <#if depid!=""&dep.depId?string==depid?string>
                <#return dep.upperId>
            </#if>
        </#list>
    </#if>
    <#return "">
</#function>
<@override name="head-styles">
    <link rel="stylesheet" href="${contextPath}/assets/plugins/ztree/css/bootstrapStyle/bootstrapStyle.css" type="text/css">
    <link rel="stylesheet" href="${contextPath}/assets/css/bootstrap.min.css">
</@override>
<@override name="page-content">
<form class="layui-form form-horizontal" role="form" method="post">
	 <div class="layui-form-search panel">
			 <input type="text" hidden="hidden" name="_STATE"/>
	         <@ctrl.Hidden path="wfUser.userId"/>
	        <@ctrl.TextboxQuery path="wfUser.userName" labelText="用户名称"/>
	        <div class="margin-5">
	           <a href="javascript:" onclick="addUser();" class="layui-btn layui-btn-sm">
	               <i class="layui-icon layui-icon-search"></i>新增用户
	           </a>
	           <a href="javascript:"  onclick="$('#pageNo').val(1);$('form:first').submit();" class="layui-btn layui-btn-sm">
	               <i class="layui-icon layui-icon-search"></i>查询
	           </a>
	        </div>
	    </div>
    	<table class="layui-table">
              <thead>
                  <tr>
                      <th class="align-center" width="10%">序号</th>
                      <th class="align-center">用户名称</th>
                      <th class="align-center">机构名称</th>
                      <th class="align-center">创建时间</th>
                      <th class="align-center">默认状态</th>
                      <th class="align-center" width="100px">操作</th>
                  </tr>
              </thead>
              <tbody>
              <#if queryResult.rows?has_content>  
                  <#list queryResult.rows as dataItem>  
                  <tr>
                      <td class="align-center" width="10%">
                          ${(pageNo-1)*pageSize+dataItem_index+1} 
                      </td>
                      <td class="align-center">${dataItem["user_name"]}</td>  
                      <td class="align-center" width="15%">${dataItem["dep_name"]}</td>
                      <td class="align-center" width="15%">${dataItem["create_time"]?datetime}</td>
                      <td class="align-center" width="10%">
                          <#if dataItem.status == 'T'>
                              <span class="label label-sm label-info">启用</span>
                          <#else>
                              <span class="label label-sm label-success">禁用</span>
                          </#if>
                      </td> 
                      <td class="align-center">
                          <div class="layui-table-cell">
		                        <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" 
		                            onclick="confirmSubmit('确定要删除‘${dataItem.user_name}’吗？', {id:'${dataItem.id}'},'del')">
		                            <i class="layui-icon layui-icon-delete"></i>删除
		                        </button>
                          </div>
                      </td>
                  </tr>
                  </#list>
              <#else>
                 <tr class="align-center">
                	<td style="color:red;font-weight:bold;" colspan="8">暂无符合条件的数据！</td>
            	 </tr>
              </#if>
              </tbody>
          </table>
          <@ctrl.pageShow (queryResult.pageCount)!0, (queryResult.pageIndex)!0 />
    </form>
    <!--模态框-->
   <div id="modal_box" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
       <div class="modal-dialog" role="document">
          <div class="modal-content">
              <div class="modal-header">
                 <h4 class="blue" id="modalTitle"></h4>
              </div>
              <div class="modal-body">
     				<ul id="selectBox" class="ztree"></ul>
              </div>
              <div class="modal-footer">
                 <input type="hidden" id="type" name="type" />
                 <button type="button" onclick="modalConfirm()" class="btn btn-success">确认</button>
                 <button type="button" onclick="modalCancel()" class="btn btn-default">取消</button>
              </div>
          </div><!-- /.modal-content -->
       </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</@override>

<@override name="page-scripts">
<script>
    $(function(){
        layui.use(['form','layer','element', 'jquery'], function(){
            var form=layui.form;
            var layer=layui.layer;
            var element = layui.element;
            var $ = layui.jquery;
            $('.js-reset').on('click', function(){
                $('#pageNo').val(1);
                $('form:first').submit();
            });
        })
    })
</script>
    
<script type="text/javascript" src="${contextPath}/assets/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${contextPath}/assets/plugins/ztree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="${contextPath}/assets/plugins/ztree/js/jquery.ztree.exedit.js"></script>
<script src="${contextPath}/assets/js/bootstrap.min.js"></script>
<script>
	function addUser(){
		var setting = {
				view: {
                    selectedMulti: false,
                },
                check: {
                    enable: true,
                    chkStyle: "checkbox",
                    chkboxType: { "Y": "", "N": "" }
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                edit: {
                    enable: false
                },
                view:{
                    selectedMulti: false
                },
                callback: {
                    onCheck: myDepandUserCheck
                }
		 };
		 var zNodes = [
		  <#if depList?has_content>
		      <#list depList as dataItem>
		          {id:"${dataItem['depId']}",pId:"${getUpperId(dataItem.depId)}",name:"${dataItem['depName']}",isParent:"true",nocheck:"true"},
		          <#list userDepList as uItem>
			          <#if dataItem.depId==uItem.dep_id>
				          {id:"${uItem.user_id}",pId:"${uItem.dep_id}",name:"${getUserName(uItem.user_id)}"},
				       </#if>
			     </#list>
		      </#list>
		  </#if>
		  
		 ];
		 
		var checkedNodes = new Array();
	    <#if queryResult.rows?has_content>
		    <#list queryResult.rows as uItem>
	    		checkedNodes.push({id:"${uItem.user_id}"});
		     </#list>
		</#if>
			
		 //3.生成树形菜单
		$.fn.zTree.init($("#selectBox"),setting,zNodes);
		var treeObj = $.fn.zTree.getZTreeObj("selectBox");
		for(var i = 0; i < checkedNodes.length; i++) {　
         // 回显选中的数据　　　
			 var node = treeObj.getNodeByParam("id", checkedNodes[i].id);//根据ID找到该节点
		     if(node != null){
		          treeObj.checkNode(node, true, false);//根据该节点选中
		     }
     	}　 
        $('#modalTitle').text("<用户>选择");
        $('#type').val("user");
        $('#modal_box').modal();
	}
	var ids = "";
	<!--模态框操作-->
    function myDepandUserCheck(event, treeId, treeNode){
    	ids = "";
        var treeObj = $.fn.zTree.getZTreeObj(treeId);
        var nodes = treeObj.getCheckedNodes(true);
        var Notnodes = treeObj.getCheckedNodes(false);
        for(var i=0;i<nodes.length;i++){
           ids=ids+","+nodes[i].id;
        }
    }
    
    <!--模态框确定-->
    function modalConfirm(){
        $('#selectBox').empty();
        jQuery.ajax({
            type     : 'POST',
            url      : '${contextPath}/workflow/user/add',
            data    : {ids:ids},
            success  : function(data){
                if(data.msg==""){
                    $('#validate-box').modal("hide");
                    location.reload();
                }else{
                	location.reload();
                    alert(data.msg);
                }
            }
        });
        modalCancel();
    }
    <!--模态框取消-->
    function modalCancel(){
        $('#modal_box').modal('hide');
        $('#selectBox').empty();
        ids = "";
    }

</script>
</@override>
<@extends name="/layout/basepage.html"/> 